﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Xemtintuc : System.Web.UI.Page
{
    BUS_News objP = new BUS_News();
    BUS_Category objC = new BUS_Category();
    protected void Page_Load(object sender, EventArgs e)
    {

        string strcid = "", strpid = "";
        Page.Title = "Xem Tin Tức";
        if (!IsPostBack)
        {
            if (Session["AdminLogin"] != null)
            {
                strcid = Request.QueryString.Get("cid");
                strpid = Request.QueryString.Get("id");
                if (strcid == null || strpid == null)
                {
                    Response.Redirect("Tintuc.aspx");
                }
                else
                {
                    LoadData(Convert.ToInt16(Request.QueryString.Get("cid")), Convert.ToInt16(Request.QueryString.Get("id")));
                }
            }
            else Response.Redirect("Dangnhap.aspx");
        }
    }
    public void LoadData(int cgid, int pid)
    {
        try
        {
            DateTime ngay;
            int Maker_Id, status;
            var dataC = objC.Category_getAllById(cgid);
            var dataP = objP.News_getAllByPid(pid);
            //var dataM = objM.Maker_getAllById(pid);
            Maker_Id = int.Parse(dataP.Rows[0]["Type"].ToString());
            //var tamM = objM.Maker_getAllById(Maker_Id);
            linkxemtt.NavigateUrl = "Xemtintuc.aspx?cid=" + cgid + "&id=" + pid;
            linksuatt.NavigateUrl = "Suatintuc.aspx?cid=" + cgid + "&id=" + pid;
            linkthemtt.NavigateUrl = "Themtintuc.aspx";
            lienKet.Text = dataC.Rows[0]["Name"].ToString();
            //tensanpham.Text = dataP.Rows[0]["Name"].ToString();
            loaitt.Text = dataC.Rows[0]["Name"].ToString();
            //nsx.Text = tamM.Rows[0]["Name"].ToString();
            tentt.Text = dataP.Rows[0]["Title"].ToString();
            EditorSumary.Text = dataP.Rows[0]["contents"].ToString();
            //giasanpham.Text = dataP.Rows[0]["Price"].ToString();
            //giakhuyenmai.Text = dataP.Rows[0]["PriceNew"].ToString();
            ngay = Convert.ToDateTime(dataP.Rows[0]["Date"].ToString());
            ngaythem.Text = ngay.ToString("dd/MM/yyyy");
            //hinhsanphamnho.ImageUrl = "~/Uploads/Product/Small/" + dataP.Rows[0]["ImageSmall"].ToString();
            hinhanhtintuc.ImageUrl = "~/Uploads/News/" + dataP.Rows[0]["Image"].ToString();
            status = int.Parse(dataP.Rows[0]["Status"].ToString());
            if (status == 1) trangthai.Text = "Mở"; else trangthai.Text = "Đóng";
        }
        catch
        {
        }

    }
}